import redi_utils as utils

annotations_data_types = ["features", "samples" ]
annotations_usage = "\tredi %s import annotations -f /local/path/to/file.tsv -t %s"

def load(dataset_id, filename, config, options):
    dataType = utils.get_dataType(dataset_id, options, annotations_usage, annotations_data_types)

    itemid = options.id
    if itemid is None: itemid = utils.get_filename(filename)

    schema = []

    # TODO : Figure out annotations data type
    rfile = open(filename)
    columnheaders = rfile.next()
    for column in columnheaders.rstrip().split("\t"):
        columnName = column.rstrip().replace(" ", "_")
        schema.append({ "name": columnName, "label": column, "type": "string" });

    tablename = "ANNOTATIONS_" + dataType.upper() + "_" + itemid
    return [{ "id": itemid, "type": "annotations", "subtype": dataType, "table": tablename, "schema": schema }]
